package net.neptech.node;

import com.alibaba.cloud.ai.graph.OverAllState;
import com.alibaba.cloud.ai.graph.action.NodeAction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;
/**
 * @Author HuangZhengmin
 * @desc  患者信息补充节点 - 处理患者对追加问题的回答
 * @Date 2025/8/19 17:39
 * @Version 1.0
 */
@Component
public class PatientInfoSupplementationNode implements NodeAction{
  private static final Logger logger = LoggerFactory.getLogger(PatientInfoSupplementationNode.class);

  @Autowired
  private ChatClient chatClient;

  @Override
  public Map<String, Object> apply(OverAllState state) {
    logger.info("进入患者信息补充节点");
    Map<String, Object> result = new HashMap<>();

    // 获取用户输入的补充信息
    String additionalInput = (String) state.value("input").orElse("");
    String previousSymptoms = (String) state.value("standardized_symptoms").orElse("");

    // 合并补充信息到症状中
    String updatedSymptoms = previousSymptoms + "\n补充信息: " + additionalInput;

    // 更新状态
    result.put("symptoms", updatedSymptoms);
    result.put("standardized_symptoms", updatedSymptoms);
    result.put("additional_info", additionalInput);
    result.put("need_additional_questions", false);

    logger.info("患者补充信息已合并");
    return result;
  }
}
